package com.liu.demo.webapi;

import com.liu.demo.pojo.StuScore;
import com.liu.demo.pojo.Student;
import com.liu.demo.pojo.Teacher;
import com.liu.demo.prository.StuScorePrository;
import com.liu.demo.service.StuScoreService;
import com.liu.demo.service.TeacherService;
import com.liu.demo.utils.RUtils;
import com.liu.demo.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/webapi/teacher")
public class teacherRestController {
    @Autowired
    private StuScoreService stuScoreService;
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/teacherList")
    public R getTeacher(){
        List<Teacher> teachers = teacherService.findAll();
        return RUtils.success(teachers);
    }

    @GetMapping("/list")
    public R getAll(){
        List<StuScore> stuScores= stuScoreService.findAll();
        return RUtils.success(stuScores);
    }

    @PostMapping("/insertScore")
    public R insertScore(StuScore stuScore){
        System.out.println(stuScore);
        stuScoreService.insertScore(stuScore);
        return RUtils.success(200,"更新成绩成功！");
    }

    @DeleteMapping("/delScore")
    public R delScore(StuScore stuScore){
        stuScoreService.delScore(stuScore);
        return RUtils.success(200,"删除成功！");
    }

    @PostMapping("/upScore")
    public R upScore(StuScore stuScore){
        stuScoreService.upScore(stuScore);
        return RUtils.success(200,"更新成绩成功！");
    }

    @GetMapping("/getScore/{id}")
    public StuScore getScore(@PathVariable Integer id){
        StuScore stuScore = stuScoreService.finByIdLike(id);
        return stuScore;
    }

    @GetMapping("/getSno/{sno}")
    public R getSno(@PathVariable Integer sno){
        List<StuScore> stuScore = stuScoreService.finBySnoLike(sno);
        return RUtils.success(stuScore);
    }

    @GetMapping("/getSname/{sname}")
    public R getSname(@PathVariable String sname){
        List<StuScore> stuScore = stuScoreService.finBySnameLike(sname);
        return RUtils.success(stuScore);
    }

    @GetMapping("/getCname/{cname}")
    public R getCname(@PathVariable String cname){
        List<StuScore> stuScore = stuScoreService.finByCnameLike(cname);
        return RUtils.success(stuScore);
    }
}
